import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:glorysoft_mobile_plugin/tool/extensions/extension.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/values/constant.dart';

import '../../values/colors.dart';
import '../../views/SubTitleBar.dart';
import '../../views/edittext/TitleEditText.dart';
import '../../views/search_drop_down_select/search_drop_down_select_widget.dart';
import 'HalfProductIntoLibController.dart';
import 'ProductIntoLibController.dart';

class HalfProductIntoLibWidget extends StatelessWidget {
  final controller = Get.put(HalfProductIntoLibController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(USER),
      ),
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: [
              SubTitleBar("半成品入库", '提交', () {
                controller.lotShip();
              }),
              TitleEditText(
                "批次ID:",
                "请扫描批次ID",
                (value) {
                  controller.lotInfo(value);
                },
                controller: controller.textEditingController,
              ),
              GetBuilder<HalfProductIntoLibController>(
                builder: (controller) {
                  return Table(
                    defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                    columnWidths: {
                      //列宽
                      0: FlexColumnWidth(1.0),
                      1: FlexColumnWidth(1.0),
                      2: FlexColumnWidth(1.0),
                      3: FlexColumnWidth(1.0),
                      4: FlexColumnWidth(1.0),
                    },
                    border: TableBorder.all(
                      color: Colors.grey,
                      width: 1.0,
                      style: BorderStyle.solid,
                    ),
                    children: getLotList(context),
                  );
                },
                id: controller.LOTID,
              ),
              GetBuilder<HalfProductIntoLibController>(
                builder: (controller) => Container(
                    height: 48,
                    padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                    color: Colors.white,
                    child: Row(
                      children: [
                        Expanded(
                          child: Text(
                            "仓库号:",
                            style: TextStyle(color: theme_blue.toColor()),
                          ),
                          flex: 3,
                        ),
                        Expanded(
                            flex: 7,
                            child: SearchDropDownSelectWidget(
                              isShowSearch: true,
                              hint: "请选择仓库",
                              onChanged: (Map<dynamic, dynamic>? value) {
                                controller.updateSelectWarehouseValue(
                                    value?[SearchDropDownSelectWidget.value]);
                              },
                              mShowList: controller.mWarehouseList,
                              selectObj: controller.selectWarehouseObj,
                            )),
                      ],
                    )),
                id: controller.WAREHOUSEID,
              ),
              Container(
                  height: 48,
                  padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                  color: Colors.white,
                  child: Row(
                    children: [
                      Expanded(
                        child: Text(
                          "位置号:",
                          style: TextStyle(color: theme_blue.toColor()),
                        ),
                        flex: 3,
                      ),
                      Expanded(
                          flex: 7,
                          child: GetBuilder<HalfProductIntoLibController>(
                              builder: (controller) {
                            return SearchDropDownSelectWidget(
                              isShowSearch: true,
                              hint: "请选择位置",
                              onChanged: (Map<dynamic, dynamic>? value) {
                                controller.updateSelectStorageValue(
                                    value?[SearchDropDownSelectWidget.value]);
                              },
                              mShowList: controller.mStorageList,
                              selectObj: controller.selectStorageObj,
                            );
                          },id: controller.STORAGEID,)),
                    ],
                  )),
            ],
          ),
        ),
      ),
    );
  }

  getLotList(BuildContext context) {
    List<TableRow> tempView = [];
    tempView.add(TableRow(
        children: [
          //增加行高
          SizedBox(
            height: 40,
            child: Align(
              alignment: Alignment.center,
              child: Text(
                '批次号',
                style: TextStyle(
                  color: theme_blue.toColor(),
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '数量',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '封装形式',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '箱号',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '产品描述',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
        ],
        //第一行样式 添加背景色
        decoration: BoxDecoration(
          color: table_head.toColor(),
        )));
    for (int i = 0; i < controller.lotList.length; i++) {
      LotEntity tempList = controller.lotList[i];
      tempView.add(TableRow(children: [
        //增加行高
        SizedBox(
          height: 40,
          child: Align(
            alignment: Alignment.center,
            child: Text(
              tempList.lOTID ?? '',
              style: TextStyle(
                color: text_black.toColor(),
              ),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            tempList.mAINQTY.toString(),
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            tempList.MAINMATTYPE ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            tempList.CARRIER_ID ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            tempList.pARTDESC ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
      ]));
    }
    return tempView;
  }
}
